Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI auth #699

Merged
merged 10 commits into from
Nov 24, 2023
Merged

UI auth #699

merged 10 commits into from
Nov 24, 2023

Conversation

serprex
Copy link
Contributor

@serprex serprex commented Nov 22, 2023

Implement the most primitive authentication scheme I could think of

Extending this can be done in future by introducing new supporting environment variables

If someone feels queasy about storing password in cookie, a 2nd env variable can be made, PEERDB_PASSWORD_TOKEN, which the cookie is set to instead of the password

On cloud we'll want to use pbkdf2 or some other key derivation function so that we never store the password anywhere. So add a PEERDB_PASSWORD_FUNCTION variable & set PEERDB_PASSWORD to {algo:'SHA512',iter:999999,salt:'random',auth:'result'} & have login handler hash password accordingly. Managed service would handle setting these environment variables on customer's setup

@serprex serprex requested a review from iskakaushik November 22, 2023 04:42
@iskakaushik
Copy link
Contributor

redirect for when password is incorrect, saying something like “invalid password, redirect to the login page”
landing page

  • if password not set show what we have today
  • if password is set, take them to a new page which then redirects to login page, for now this page can just have a text field to enter the password and handle login response.
    for the text field make the border not white.

ui/components/Password.tsx Outdated Show resolved Hide resolved
ui/app/page.tsx Outdated Show resolved Hide resolved
@serprex serprex marked this pull request as ready for review November 23, 2023 21:56
@serprex serprex changed the title UI basic auth UI auth Nov 23, 2023
@iskakaushik
Copy link
Contributor

There are some UI refinements for a later PR, but this is looking good for now. LGTM!


import { NextResponse } from 'next/server';

export default function middleware(req: NextRequest) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of something like:

const router = createEdgeRouter<NextRequest, NextFetchEvent>();

router.use('/', async (request) => {
  let path = request.nextUrl.pathname;
  let excludedPaths = ['/api/auth/callback', '/api/auth/login'];
  if (!excludedPaths.includes(path)) {
    // ...
    return authMiddleware(request);
  } else {
    return NextResponse.next();
  }
});

export function middleware(request: NextRequest, event: NextFetchEvent) {
  return router.run(request, event);
}

export const config = {
  matcher: [
    // Match everything other than static assets
    '/((?!_next/static|_next/image|favicon.ico).*)',
  ],
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add export const config but for now the rest seems unnecessary

Copy link
Contributor

@iskakaushik iskakaushik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left one comment for your consideration, but overall good

@serprex serprex merged commit b205f0a into main Nov 24, 2023
12 checks passed
@serprex serprex deleted the ui-basic-auth branch December 19, 2023 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants